/*
 * File Name : group.cpp
 * Auther : dream.liuguobiao
 * Create Date : 2010-5-11
 * Last Edit : 2010-5-14
 */
#include "user.h"
#include "group.h"
#include <vector>

group::group(std::string new_name)
:name(new_name),ID(500),next(NULL)
{
}

group::group(std::string new_name, int new_ID)
:name(new_name),ID(new_ID),next(NULL)
{
}

group::~group(){
  std::vector<user *>::iterator user;
  for(user = users.begin() ;user < users.end(); user++){
    (*user)->remove_group(this);
  }
}

int group::get_ID()
{
  return ID;
}

bool group::set_ID(int new_ID)
{
  ID = new_ID;
  return 0;
}

group *group::get_next_group()
{
  return next;
}

bool group::set_next_group( group *new_next_group )
{
  next = new_next_group ;
  return 0;
}

std::string *group::get_name()
{
  return &name;
}

bool group::remove_user( user *delete_user ){
  std::vector<user *>::iterator user = users.begin();
  for(; user < users.end() ; user ++){
    if( *user == delete_user )
      users.erase(user);
  }
  return 0;
}

bool group::insert_user( user *insert_user ){
  users.push_back( insert_user );
  return 0;
}
